package com.gitee.dolt.core.base.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author LYH
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Accessors(chain = true)
@EqualsAndHashCode(of = "id")
public class SuperEntity<T> implements Serializable {
    private static final long serialVersionUID = -4603650115461757622L;
    public static final String FIELD_ID = "id";
    public static final String CREATE_TIME = "createTime";
    public static final String CREATE_TIME_COLUMN = "create_time";
    public static final String CREATED_BY = "createdBy";
    public static final String CREATED_BY_COLUMN = "created_by";


    @TableId(value = "id", type = IdType.INPUT)
    @ApiModelProperty(value = "主键")
    @NotNull(message = "id不能为空", groups = SuperEntity.Update.class)
    @Null(message = "id必需为空", groups = SuperEntity.Save.class)
    protected T id;

    @ApiModelProperty(value = "创建时间")
    @Null(message = "创建时间必需为空")
    @TableField(value = CREATE_TIME_COLUMN, fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER)
    protected LocalDateTime createTime;

    @ApiModelProperty(value = "创建人ID")
    @Null(message = "创建人必需为空")
    @TableField(value = CREATED_BY_COLUMN, fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER)
    protected T createdBy;

    /**
     * 保存和缺省验证组
     */
    public interface Save extends Default {

    }

    /**
     * 更新和缺省验证组
     */
    public interface Update extends Default {

    }


}

